package com.gxa.admin.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.gxa.admin.mapper.VipMapper;
import com.gxa.admin.pojo.dto.VipDto;
import com.gxa.admin.service.VipService;
import com.gxa.admin.utils.QueryResult;
import com.gxa.pojo.Vip;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.sql.Timestamp;
import java.util.List;

/**
 * @author lch
 * @date 2024/3/20 15:32
 * @description 会员等级实现类
 **/
@Service
public class VipServiceImpl implements VipService {

    @Resource
    private VipMapper vipMapper;

    /**
     * 查询所有会员等级
     * @param vipDto
     * @return
     */
    @Override
    public QueryResult getAllVipLevel(VipDto vipDto) {

        //分页查询
        //import com.github.pagehelper.Page;
        //import com.github.pagehelper.PageHelper;
        Page<Vip> page= PageHelper.startPage(vipDto.getPage(), vipDto.getLimit());

        //查询会员等级
        List<Vip> vipList = this.vipMapper.queryAllVipLevel(vipDto);

        //封装返回数据
        QueryResult queryResult = new QueryResult();
        queryResult.setData(vipList);
        queryResult.setCount(page.getTotal());

        return queryResult;
    }


    /**
     * 添加会员等级
     * @param vipDto
     * @return
     */
    @Override
    public int addVipLevel(VipDto vipDto) {

        //获取当前时间
        Timestamp timestamp=new Timestamp(System.currentTimeMillis());
        vipDto.setCreated(timestamp);

        return this.vipMapper.insertVipLevel(vipDto);
    }


    /**
     * 更新会员等级
     * @param vipDto
     * @return
     */
    @Override
    public int updateVipLevel(VipDto vipDto) {

        return this.vipMapper.updateVipLevel(vipDto);
    }


    /**
     * 根据id删除会员等级
     * @param vipId
     * @return
     */
    @Override
    public int deleteVipLevel(Integer vipId) {
        //判断vipId是否为空
        if(vipId==null){
            return -1;
        }

        return this.vipMapper.deleteVipLevel(vipId);
    }


    /**
     * 根据id查询会员等级
     * @param vipId
     * @return
     */
    @Override
    public Vip getVipById(Integer vipId) {

        //判断vipId是否为空
        if(vipId==null){
            return null;
        }
        return this.vipMapper.queryVipById(vipId);
    }
}
